﻿using System;
using System.ComponentModel;
using System.Windows;
using WPFExcelReport.Helpers;

namespace WPFExcelReport
{
    public partial class UIMJOB : UIJOB
    {
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
        }
        public override void OnLoadChg(bool value)
        {
            base.OnLoadChg(value);
        }
        public override void LOADBYAUF()
        {
            if (!IsCanLoad)
                return;
            if (ORDERNUM.Length < 1)
                return;
            dwData = TBMain.NewRow();
            dwData["ABFMANDANT"] = app.Mandant;
            dwData["ABAID"] = ORDERNUM;
            SResult = TMV.QTMKRF01(dwData);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            base.SaveCommand(sender, e);
        }
        public override void OnDTSTARTChg(string value)
        {
            if (dwMaster == null)
                return;
            TMV.MKFPLDATV = DTSTART;
            base.OnDTSTARTChg(value);
        }
        public override void OnQTYChg(double value)
        {
            DateTime JobStart = new DateTime();
            DateTime JobEnd = new DateTime();
            TMV.ABFAMASCHZT = QTY;
            Helper.GetDateTime(ref JobStart, TMV.MKFPLDATV, TMV.MKFPLTIME);
            JobEnd = JobStart.AddMinutes(TMV.ABFAMASCHZT);
            string jdstart = "", jtstart = "";
            Helper.GetStdDate(ref jdstart, ref jtstart, JobEnd);
            dwJob["ENDATE"] = jdstart;
            dwJob["ENDTIME"] = jtstart;
            TMV.UpdateICC_MKRF(dwMaster, 1);
            base.OnQTYChg(value);
        }
        public void btnRefreshEvents_Click(object sender, RoutedEventArgs e)
        {
            if (dwJob == null)
                return;
            dwJob["JOBTYPE"] = "X";
            string StartDate = dwJob["MKFPLDATV"].ToString();
            string StartTime = dwJob["MKFPLTIME"].ToString();
            string ProcessTime = dwJob["ABFAMASCHZT"].ToString();
            int year = 2012, month = 1, day = 1, hh = 0, mm = 0;
            Helper.SplitDate(ref year, ref month, ref day, StartDate);
            Helper.SplitTime(ref hh, ref mm, StartTime);
            DateTime StartDateTime = new DateTime(year, month, day, hh, mm, 0);
            DateTime EndDateTime = StartDateTime.AddMinutes(Convert.ToDouble(ProcessTime));
            string EndDate = "", EndTime = "";
            Helper.GetStdDate(ref EndDate, ref EndTime, EndDateTime);
            dwJob["ENDATE"] = EndDate;
            dwJob["ENDTIME"] = EndTime;
        }
    }
}
